/**
 * Project Name:relation-framework-proj
 * Package Name:com.relation.framework.common.component.retry
 * Date:2019/1/11下午12:09
 * Copyright (c) 2019, www.relation.com All Rights Reserved
 */
package com.eci.context.context.feign;

import feign.RetryableException;
import feign.Retryer;


public class EciRetryer extends Retryer.Default {
    private long period;
    private long maxPeriod;
    private int maxAttempts;


    public EciRetryer(long period, long maxPeriod, int maxAttempts) {
        super(period, maxPeriod, maxAttempts);
        this.period = period;
        this.maxPeriod = maxPeriod;
        this.maxAttempts = maxAttempts;
    }

    /**
     * if retry is permitted, return (possibly after sleeping). Otherwise propagate the exception.
     *
     * @param e
     */
    @Override
    public void continueOrPropagate(RetryableException e) {
        if (!e.getMessage().contains("Failed to connect")) {
            throw e;
        }
        super.continueOrPropagate(e);
    }

    @Override
    public Retryer clone() {
        return new EciRetryer(period, maxPeriod, maxAttempts);
    }

}
